<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="初识redis, 凌">
    <meta name="description" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>初识redis | 凌</title>
    <link rel="icon" type="image/png" href="/blog/favicon.png">

    <link rel="stylesheet" type="text/css" href="https://sky508.gitee.io/blog/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="https://sky508.gitee.io/blog/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="https://sky508.gitee.io/blog/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="https://sky508.gitee.io/blog/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="https://sky508.gitee.io/blog/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/blog/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/blog/css/my.css">

    <script src="https://sky508.gitee.io/blog/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 4.2.0"><link rel="stylesheet" href="/blog/css/prism.css" type="text/css">
<link rel="stylesheet" href="/blog/css/prism-line-numbers.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/blog/" class="waves-effect waves-light">
                    
                    <img src="" data-original="https://glh508-blog-img.oss-cn-beijing.aliyuncs.com/banner/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">凌</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/blog/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>联系</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="" data-original="https://glh508-blog-img.oss-cn-beijing.aliyuncs.com/banner/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">凌</div>
        <div class="logo-desc">
            
            Never really desperate, only the lost of the soul.
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/blog/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/blog/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			联系
		</a>
          
        </li>
        
        
    </ul>
</div>


        </div>

        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('https://glh508-blog-img.oss-cn-beijing.aliyuncs.com/img/10.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">初识redis</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="https://sky508.gitee.io/blog/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        height: calc(100vh - 250px);
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/blog/tags/redis/">
                                <span class="chip bg-color">redis</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/blog/categories/NoSQL/" class="post-category">
                                NoSQL
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2020-04-10
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2020-05-13
                </div>
                

                

                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h3 id="一、初始Redis"><a href="#一、初始Redis" class="headerlink" title="一、初始Redis"></a>一、初始Redis</h3><p>１．基本知识</p>
<p>Redis:REmote DIctionary Server(远程字典服务器)</p>
<p>是完全开元免费的，用c语言开发的，遵守BSD协议，是一个高性能的（key-value）分布式内存数据库，基于内存运行并支持持久化的NoSQL数据库，是当前最热门的NoSQL数据库之一，也被人们称为数据结构服务器。</p>
<p>２．特点：</p>
<p>１）支持数据的持久化，可以将内存中的数据保持在磁盘中，重启的时候可以再次加载进行使用；</p>
<p>２）不仅仅支持简单的key-value类型的数据，同时还提供string、list（相当于java中的有序可重复list）、set（相当于java中的无序不可重复）、zset（更接近于sorted map）、hash（相当于map等集合）等数据结构的存储；操作都是原子性的（即不可拆分不可打断）</p>
<p>３）支持数据的备份，即master-slave（主从）模式的数据备份；（为了读写分离，一般能写的就能读，但是只能读的就不能写）</p>
<p>３．作用</p>
<p>１）内存存储和持久化：redis支持异步将内存中的数据写到硬盘上，同时不影响继续服务；</p>
<p>２）取最新的N个数据的操作，如：可以将最新的10条评论的ID放在Redis的list集合中；</p>
<p>３）模拟类似于HttpSession这种需要设置定时过期时间的功能；</p>
<p>４）发布、订阅消息系统；</p>
<p>５）定时器、计数器</p>
<p>４．使用</p>
<p>数据类型、基本操作和配置，持久化和复制，RDB/AOF，事务的控制，复制</p>
<p>５．应用场景</p>
<p>１）配合关系型数据库做高速缓存：高频次，热门访问的数据，降低数据库IO，分布式架构，做session共享。</p>
<p>２）由于其拥有持久化能力，利用其多样的数据结构存储特定的数据。</p>
<p><img src="" data-original="https://glh508-blog-img.oss-cn-beijing.aliyuncs.com/img/redis-2.png" alt=""></p>
<h3 id="二、命令的基本使用"><a href="#二、命令的基本使用" class="headerlink" title="二、命令的基本使用"></a>二、命令的基本使用</h3><p>１．安装级简单的进入使用</p>
<pre class="line-numbers language-java"><code class="language-java"><span class="token number">1.1</span> 简单安装redis<span class="token punctuation">,</span>使用如下命令：
    <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">.</span>tar <span class="token operator">-</span>zxvf redis<span class="token operator">-</span><span class="token number">5.0</span><span class="token punctuation">.</span><span class="token number">7</span><span class="token punctuation">.</span>tar<span class="token punctuation">.</span><span class="token function">gz</span>
    <span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">.</span>cp redis<span class="token operator">-</span><span class="token number">5.0</span><span class="token punctuation">.</span><span class="token number">7</span> <span class="token operator">/</span>home<span class="token operator">/</span><span class="token function">glh</span>
    <span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">.</span>cd redis<span class="token operator">-</span><span class="token number">5.0</span><span class="token punctuation">.</span><span class="token function">7</span>
    <span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">.</span>make   <span class="token comment" spellcheck="true">//这一步会出错，原因是缺少gcc、gcc-c++，自行安装就行</span>
    <span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">.</span>sudo make <span class="token function">install</span>
    <span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">.</span>进入redis<span class="token operator">-</span>cli客户端命令行模式之后可以输入shutdown关闭服务端，然后退出客户端就行了<span class="token punctuation">;</span>
        或者直接在命令行输入一下命令：redis<span class="token operator">-</span>cli shutdown；但是要是设置了密码，好像就关不了，还是先使用ps <span class="token operator">-</span>ef <span class="token operator">|</span> grep redis<span class="token operator">-</span>server，然后使用kill <span class="token operator">-</span><span class="token number">9</span> pid号结束redis进程。
<span class="token number">1.2</span> 启动redis
   直接在命令行输入就行：
　　　<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">.</span>redis<span class="token operator">-</span><span class="token function">server</span>
   <span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">.</span>以特定的配置文件启动：redis<span class="token operator">-</span>server <span class="token punctuation">.</span>/redis<span class="token punctuation">.</span><span class="token function">conf</span>
   <span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">.</span>默认启动redis客户端：redis<span class="token operator">-</span><span class="token function">cli</span>
   <span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">.</span>访问特定的ip的redis服务器：redis<span class="token operator">-</span>cli <span class="token operator">-</span>h <span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span> <span class="token operator">-</span>p <span class="token function">6379</span>
   <span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">.</span>redis设置密码：编辑redis<span class="token punctuation">.</span>conf中的requirepass字段，设置为requirepass <span class="token number">123456</span>，也就是密码为<span class="token function">123456</span>
   <span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</span><span class="token punctuation">.</span>默认<span class="token number">16</span>个数据库，下标从<span class="token number">0</span>开始，使用select index来选择数据库，例如select <span class="token number">1</span><span class="token punctuation">;</span>选择第二个数据库<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<ol start="2">
<li><p>redis是单线程＋多路IO复用技术，其实就是给它一个监视效果，只要监测到这个任务准备完毕就可以让redis对其进行处理，不要等待。</p>
<p>一个搞笑例子：</p>
<pre class="line-numbers language-properties"><code class="language-properties">阻塞IO：给女神发一条短信，说我来找你了，然后默默等待女神下楼，这个期间你除了等待你不会做其他事情，属于备胎做法；
非阻塞IO：给女神发短信，如果不会就一直发，一直发到女神下楼，这个期间你除了发短信不会干其他事情，属于专一做法；
IO多路复用：是找一个宿管大妈来帮你监视下楼的女生，这个期间你可以做一些其他事情，例如可以玩玩手机，上个厕所等等，IO复用又包括select、poll、epoll这三种模式；
    select大妈：每一个女生下楼，select大妈都不知道这个是不是你的女神，他需要一个一个的询问，并且select大妈能力有限，最多一次帮你把监视1024个妹子；
    poll大妈：不限制盯着女生的数量，只要是经过宿舍楼门口的女生，都会帮你去问是不是你的女神；
    epoll大妈：不限制盯着女生的数量，并且有人不需要一个个去问，那么怎么做？eppoll大妈会为每一个进宿舍楼的女生脸上贴上一个字条，上满写上女生的名字，只要是女生下楼了，epoll大妈就知道这个是不是你的女神了，然后大妈再通知你。
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>多路复用就是指使用一个线程来检查多个文件描述符(Socket)的就绪状态，比如调用select和poll函数，传入多个文件描述符，如果有一个文件描述符就绪，则返回，否则则色直到超时。得到就绪状态后进行真正的操作可以在同一个线程里执行，也可以启动线程执行（比如使用线程池）。</p>
</li>
</ol>
<h3 id="三、redis数据类型"><a href="#三、redis数据类型" class="headerlink" title="三、redis数据类型"></a>三、redis数据类型</h3><p>key+(string/set/list/hash/zset)</p>
<ol>
<li><p>基础操作</p>
<pre class="line-numbers language-java"><code class="language-java">keys <span class="token operator">*</span>        <span class="token comment" spellcheck="true">//查询当前数据库的所有键</span>
exists <span class="token operator">&lt;</span>key<span class="token operator">></span>    <span class="token comment" spellcheck="true">//判断某个键是否存在</span>
type <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//查看键的类型</span>
del <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//删除某个键</span>
expire <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>seconds<span class="token operator">></span>        <span class="token comment" spellcheck="true">//为键值设置过期时间，单位秒</span>
ttl <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//查看还有多少秒过期，-1表示永不过期，-2表示已过期</span>
dbsize            <span class="token comment" spellcheck="true">//查看当前数据库的key的数量</span>
flushdb            <span class="token comment" spellcheck="true">//清空当前库</span>
flushall        <span class="token comment" spellcheck="true">//通杀全部库,虽然也可以恢复，最好不要用，就是清空16个库</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
</li>
</ol>
<p>2.五大数据类型</p>
<p>1).  <strong>String</strong>（用的最多）</p>
<p>。String是redis的最基本类型，可以理解一个key对应一个value。(与Mencached一模一样的类型)</p>
<p>。String类型是二进制安全的，意味着redis的string可以包含任何数据，比如jpg图片、序列化对象。</p>
<p>。String类型是redis最基本的数据类型，一个redis字符串（key）对应的value最多可以使512M。</p>
<p><strong>操作指令</strong></p>
<pre class="line-numbers language-java"><code class="language-java">get <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//查询对应键值</span>
set <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>value<span class="token operator">></span>        <span class="token comment" spellcheck="true">//添加键值对</span>
append <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>value<span class="token operator">></span>        <span class="token comment" spellcheck="true">//将给定的&lt;value>追加到原值的结尾</span>
strlen <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//获得值的长度</span>
setnx <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>value<span class="token operator">></span>        <span class="token comment" spellcheck="true">//只有当key不存在时设置key的值</span>
incr <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//将key中存储的数字值增１，只能对数字值操作，如果为空，新增值为１</span>
decr <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//将key中存储的数字值减１，只能对数字值操作，如果为空，新增值为－１</span>
incrby<span class="token operator">/</span>decrby <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>步长<span class="token operator">></span>        <span class="token comment" spellcheck="true">//将key中存储的数字值增/减，自定义步长</span>

mset <span class="token operator">&lt;</span>key1<span class="token operator">></span> <span class="token operator">&lt;</span>value1<span class="token operator">></span> <span class="token operator">&lt;</span>key2<span class="token operator">></span> <span class="token operator">&lt;</span>value2<span class="token operator">></span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>        <span class="token comment" spellcheck="true">//同时设置一个或者多个key-value对</span>
mget <span class="token operator">&lt;</span>key1<span class="token operator">></span> <span class="token operator">&lt;</span>key2<span class="token operator">></span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>        <span class="token comment" spellcheck="true">//同时获取一个或者多个value</span>
msetnx <span class="token operator">&lt;</span>key1<span class="token operator">></span> <span class="token operator">&lt;</span>value1<span class="token operator">></span> <span class="token operator">&lt;</span>key2<span class="token operator">></span> <span class="token operator">&lt;</span>value2<span class="token operator">></span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>        <span class="token comment" spellcheck="true">//同时设置一个或者多个key-value对，当且仅当所有给定的key都不存在，不然一个都会进行添加</span>

getrange <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>起始位置<span class="token operator">></span> <span class="token operator">&lt;</span>结束位置<span class="token operator">></span>        <span class="token comment" spellcheck="true">//获得值的范围，类似于java中的substring,左闭右开</span>
setrange <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>起始位置<span class="token operator">></span> <span class="token operator">&lt;</span>value<span class="token operator">></span>        <span class="token comment" spellcheck="true">//用&lt;value>覆写&lt;key>当前位置所存储的字符串值，从&lt;起始位置>开始</span>

setex <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>过期时间<span class="token operator">></span> <span class="token operator">&lt;</span>value<span class="token operator">></span>        <span class="token comment" spellcheck="true">//设置键值的同时，设置过期时间，单位秒</span>
getset <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>value<span class="token operator">></span>        <span class="token comment" spellcheck="true">//以新换旧，设置了新值同时获取了旧值</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p><strong>原子性</strong>：所谓的原子操作是指不会被线程调度机制打断的操作，一旦开始，就一直运行到结束，中间不会有任何context switch（切换到另一个线程）。</p>
<p>​    （１）在单线程中，能够在单条指令中完成的操作都可以认为是“原子操作”，因为中断只能发生于指令之间；</p>
<p>​    （２）在多线程中，不能被其他进程（线程）打断的操作就叫原子操作。</p>
<p><strong>redis单命令的原子性主要是得益于redis的单线程</strong></p>
<p>举例：</p>
<pre class="line-numbers language-java"><code class="language-java"><span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> set a aa
OK
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> set b bb
OK
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> set c cc
OK
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> get a
<span class="token string">"aa"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> strlen <span class="token function">a</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> append a <span class="token function">bbcc</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> get a
<span class="token string">"aabbcc"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> strlen <span class="token function">a</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> setnx a <span class="token function">aabb</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> setnx d <span class="token function">ddcc</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> get d
<span class="token string">"ddcc"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> incr <span class="token function">a</span>
<span class="token punctuation">(</span>error<span class="token punctuation">)</span> ERR value is not an integer or out of range
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> incr <span class="token function">e</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> get e
<span class="token string">"1"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> incr <span class="token function">e</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> get e
<span class="token string">"2"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> decr <span class="token function">f</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token number">1</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> decr <span class="token function">f</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token number">2</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> decrby f <span class="token function">3</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token number">5</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> mset a1 aa1 b1 bb1
OK
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> keys <span class="token operator">*</span>
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"b1"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"a1"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"d"</span>
<span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"e"</span>
<span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
<span class="token number">6</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
<span class="token number">7</span><span class="token punctuation">)</span> <span class="token string">"f"</span>
<span class="token number">8</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> mget a1 b1
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"aa1"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"bb1"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> mget a a1 b b1
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"aabbcc"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"aa1"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"bb"</span>
<span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"bb1"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> msetnx aa1 aaa1 bb1 bbb1 a <span class="token function">aas</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> msetnx aa1 aaa1 bb1 <span class="token function">bbb1</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> set ab abcdefhg
OK
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> get ab
<span class="token string">"abcdefhg"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> getrange ab <span class="token number">1</span> <span class="token number">5</span>
<span class="token string">"bcdef"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> setrange ab <span class="token number">2</span> <span class="token function">v</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">8</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> get ab
<span class="token string">"abvdefhg"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> setex k1 <span class="token number">10</span> v1  <span class="token comment" spellcheck="true">//与expire作用类似</span>
OK
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> ttl <span class="token function">k1</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> ttl <span class="token function">k1</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> ttl <span class="token function">k1</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> ttl <span class="token function">k1</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> ttl <span class="token function">k1</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token number">2</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> keys <span class="token operator">*</span>
 <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"b1"</span>
 <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"d"</span>
 <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"e"</span>
 <span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"ab"</span>
 <span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
 <span class="token number">6</span><span class="token punctuation">)</span> <span class="token string">"bb1"</span>
 <span class="token number">7</span><span class="token punctuation">)</span> <span class="token string">"a1"</span>
 <span class="token number">8</span><span class="token punctuation">)</span> <span class="token string">"aa1"</span>
 <span class="token number">9</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
<span class="token number">10</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
<span class="token number">11</span><span class="token punctuation">)</span> <span class="token string">"f"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> getset ab qwer
<span class="token string">"abvdefhg"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> get ab
<span class="token string">"qwer"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>2). <strong>list</strong></p>
<p>。单键多值</p>
<p>。redis列表是简单的字符串列表，按照插入顺序排序，你可以添加一个元素到列表的头部（左边）或者尾部（右边）</p>
<p>。底层：双向链表，对两端的操作性能很高，通过索引下标的操作中间的节点性能会较差</p>
<p><strong>操作指令</strong></p>
<pre class="line-numbers language-java"><code class="language-java">lpush<span class="token operator">/</span>rpush <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>value1<span class="token operator">></span> <span class="token operator">&lt;</span>value2<span class="token operator">></span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>        <span class="token comment" spellcheck="true">//从左边/右边插入一个或者多个值</span>
lpop<span class="token operator">/</span>rpop <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//从左边/右边吐出一个值，值在键在，值光键亡</span>
rpoplpush <span class="token operator">&lt;</span>key1<span class="token operator">></span> <span class="token operator">&lt;</span>key2<span class="token operator">></span>        <span class="token comment" spellcheck="true">//从&lt;key1>列表右边吐出一个值，插到&lt;key2>中</span>
lrange <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>start<span class="token operator">></span> <span class="token operator">&lt;</span>stop<span class="token operator">></span>        <span class="token comment" spellcheck="true">//按照索引下标获得元素（从左到右）</span>
lindex <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>value<span class="token operator">></span>        <span class="token comment" spellcheck="true">//按照索引下标获得元素（从左到右）</span>
llen <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//获得列的长度</span>
linsert <span class="token operator">&lt;</span>key<span class="token operator">></span> before <span class="token operator">&lt;</span>value<span class="token operator">></span> <span class="token operator">&lt;</span>newvalue<span class="token operator">></span>        <span class="token comment" spellcheck="true">//在&lt;value>的前面/后面插入&lt;newvalue>插入值</span>
lrem <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>n<span class="token operator">></span> <span class="token operator">&lt;</span>value<span class="token operator">></span>        <span class="token comment" spellcheck="true">//从左边删除n个value(从左到右)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>举例：</p>
<pre class="line-numbers language-java"><code class="language-java"><span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lpush list1 <span class="token number">123</span> abc a1b2　<span class="token comment" spellcheck="true">//相当于从中间往表头添加</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> rpush list1 ccdd <span class="token number">234</span> ccc　<span class="token comment" spellcheck="true">//相当于从中间往表尾添加</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lpop list1　<span class="token comment" spellcheck="true">//从表头数a1b2为第一个数</span>
<span class="token string">"a1b2"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> rpop list1　<span class="token comment" spellcheck="true">//从表尾数ccc为最后一位数</span>
<span class="token string">"ccc"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lrange list1 <span class="token number">0</span> <span class="token operator">-</span><span class="token number">1</span>
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"abc"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"123"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"ccdd"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lindex list1 <span class="token number">2</span>
<span class="token string">"ccdd"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> llen <span class="token function">list1</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> linsert list1 before <span class="token number">123</span> <span class="token function">xyzd</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">4</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lrange list1 <span class="token number">0</span> <span class="token operator">-</span><span class="token number">1</span>
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"abc"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"xyzd"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"123"</span>
<span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"ccdd"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> linsert list1 before <span class="token number">123</span> <span class="token function">xyzd</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">4</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lrange list1 <span class="token number">0</span> <span class="token operator">-</span><span class="token number">1</span>
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"abc"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"xyzd"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"123"</span>
<span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"ccdd"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lpush list1 <span class="token function">abc</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lrange list1 <span class="token number">0</span> <span class="token operator">-</span><span class="token number">1</span>
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"abc"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"abc"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"xyzd"</span>
<span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"123"</span>
<span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"ccdd"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lrem list1 <span class="token number">2</span>  abc  <span class="token comment" spellcheck="true">//数字为正数，从左边开始删</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lrange list1 <span class="token number">0</span> <span class="token operator">-</span><span class="token number">1</span>
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"xyzd"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"123"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"ccdd"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lrange list1 <span class="token number">0</span> <span class="token operator">-</span><span class="token number">1</span>
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"xyzd"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"123"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"ccdd"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lrem list1 <span class="token operator">-</span><span class="token number">1</span>  ccdd　　<span class="token comment" spellcheck="true">//数字为正数，从右边开始删</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> lrange list1 <span class="token number">0</span> <span class="token operator">-</span><span class="token number">1</span>
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"xyzd"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"123"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>3). <strong>set</strong></p>
<p>。set可以自动排重，并且set提供了判断某个成员是否存在一个set集合内的重要接口；</p>
<p>。redis的set是string的无序集合，他底层实际上就是一个value为null的hash表，所以添加、删除、查找的复杂度都是O(1)；</p>
<p><strong>操作命令</strong></p>
<pre class="line-numbers language-java"><code class="language-java">sadd <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>value1<span class="token operator">></span> <span class="token operator">&lt;</span>value2<span class="token operator">></span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>        <span class="token comment" spellcheck="true">//将一个或多个member元素加入到集合key中，已经存在于集合中的member元素将被忽略</span>
smembers <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//取出该集合的所有值</span>
sismember <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>value<span class="token operator">></span>        <span class="token comment" spellcheck="true">//判断集合&lt;key>是否含有该&lt;value>值，有就返回１，没有就返回０</span>
scard <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//返回该集合的元素个数</span>
srem <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>value1<span class="token operator">></span> <span class="token operator">&lt;</span>value2<span class="token operator">></span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>        <span class="token comment" spellcheck="true">//删除集合中的某个元素</span>
spop <span class="token operator">&lt;</span>key<span class="token operator">></span>        <span class="token comment" spellcheck="true">//随机从该集合中吐出一个值,就是从这个集合中删除了这个元素</span>
srandmember <span class="token operator">&lt;</span>key<span class="token operator">></span> <span class="token operator">&lt;</span>n<span class="token operator">></span>        <span class="token comment" spellcheck="true">//随机从该集合中取出n个值，不会从集合中删除</span>
sinter <span class="token operator">&lt;</span>key1<span class="token operator">></span> <span class="token operator">&lt;</span>key2<span class="token operator">></span>        <span class="token comment" spellcheck="true">//返回两个集合的交集元素</span>
sunion <span class="token operator">&lt;</span>key1<span class="token operator">></span> <span class="token operator">&lt;</span>key2<span class="token operator">></span>        <span class="token comment" spellcheck="true">//返回两个集合的并集元素</span>
sdiff <span class="token operator">&lt;</span>key1<span class="token operator">></span> <span class="token operator">&lt;</span>key2<span class="token operator">></span>        　<span class="token comment" spellcheck="true">//返回两个集合的差集元素(&lt;key1>减去（&lt;key1>与&lt;key2>的交集)，反之则反之)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>示例：</p>
<pre class="line-numbers language-java"><code class="language-java"><span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> sadd s1 v1 v2 v3 v4 <span class="token function">v5</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> smembers <span class="token function">s2</span>
<span class="token punctuation">(</span>empty list or set<span class="token punctuation">)</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> smembers s1
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"v2"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"v4"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"v3"</span>
<span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"v1"</span>
<span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"v5"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> sismember s1 <span class="token function">v3</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> sismember s1 <span class="token function">v11</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> scard <span class="token function">s1</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> srem s1 v2 <span class="token function">v4</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> smembers s1
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"v5"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"v1"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"v3"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> spop s1
<span class="token string">"v5"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> smembers s1
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"v1"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"v3"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> sadd s1 z1 z2 <span class="token function">z3</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> smembers s1
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"z2"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"z3"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"v1"</span>
<span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"z1"</span>
<span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"v3"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> srandmember s1 <span class="token number">3</span>
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"z2"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"v1"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"z1"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> sadd s2 v1 v2 v3 v4 v5 <span class="token function">v6</span>
<span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> sinter s1 s2
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"v1"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"v3"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> sunion s1 s2
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"v5"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"v2"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"z2"</span>
<span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"z3"</span>
<span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"v1"</span>
<span class="token number">6</span><span class="token punctuation">)</span> <span class="token string">"z1"</span>
<span class="token number">7</span><span class="token punctuation">)</span> <span class="token string">"v4"</span>
<span class="token number">8</span><span class="token punctuation">)</span> <span class="token string">"v3"</span>
<span class="token number">9</span><span class="token punctuation">)</span> <span class="token string">"v6"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> sdiff s1 s2
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"z1"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"z2"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"z3"</span>
<span class="token number">127.0</span><span class="token punctuation">.</span><span class="token number">0.1</span><span class="token operator">:</span><span class="token number">6379</span><span class="token operator">></span> sdiff s2 s1
<span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"v5"</span>
<span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"v2"</span>
<span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"v6"</span>
<span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"v4"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>4). <strong>hash</strong></p>
<p>。redis hash是一个键值对集合</p>
<p>。redis hash是一个string类型的field和value的映射表，hash特别适合用于存储对象</p>
<p>。类似于java里面的Map&lt;String,String&gt;</p>
<p><strong>操作命令</strong></p>

            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/blog/about" rel="external nofollow noreferrer">glh</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://blog.glh508.top/blog/post/67d51f09.html">https://blog.glh508.top/blog/post/67d51f09.html</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/blog/about" target="_blank">glh</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/blog/tags/redis/">
                                    <span class="chip bg-color">redis</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/blog/libs/share/css/share.min.css">
<div id="article-share">

    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="" data-original="/blog/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="" data-original="/blog/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments textarea {
        box-sizing: border-box;
        background: url("/blog/medias/comment_bg.png") 100% 100% no-repeat;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #4cbf30;
        font-weight: 500;
        text-decoration: none;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; padding-left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="vcomments" class="card-content" style="display: grid">
    </div>
</div>

<script src="/blog/libs/valine/av-min.js"></script>
<script src="https://sky508.gitee.io/blog/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: 't5C6WwDat4msTdtyG9E8lSU7-gzGzoHsz',
        appKey: 'xE7bK8SjGw38UDPb7vLi5qsb',
        notify: 'true' === 'true',
        verify: 'true' === 'true',
        visitor: 'true' === 'true',
        avatar: 'mm',
        pageSize: '10',
        lang: 'zh-cn',
        placeholder: '欢迎留下您的讨论'
    });
</script>

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/blog/post/d15a4a60.html">
                    <div class="card-image">
                        
                        
                        <img src="" data-original="https://glh508-blog-img.oss-cn-beijing.aliyuncs.com/img/15.jpg" class="responsive-img" alt="解决进入docker之后无法输入中文的简单解决方法">
                        
                        <span class="card-title">解决进入docker之后无法输入中文的简单解决方法</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            在进入docker的命令上设置语言编码格式：
docker exec -it 容器名称 env LANG=C.UTF-8 bash   
注意：LANG=C.UTF-8大写，不要小写感谢dockone这条讨论带来的解决办法dockerone
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2020-04-11
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/blog/categories/%E6%8A%80%E5%B7%A7%E4%BB%8B%E7%BB%8D/" class="post-category">
                                    技巧介绍
                                </a>
                            
                            <a href="/blog/categories/%E6%8A%80%E5%B7%A7%E4%BB%8B%E7%BB%8D/docker/" class="post-category">
                                    docker
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/blog/tags/docker/">
                        <span class="chip bg-color">docker</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/blog/post/76a1ede8.html">
                    <div class="card-image">
                        
                        <img src="" data-original="https://glh508-blog-img.oss-cn-beijing.aliyuncs.com/img/bg01.png" class="responsive-img" alt="leetcode做题记录">
                        
                        <span class="card-title">leetcode做题记录</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Java一、跳跃游戏题目描述：给定一个非负整数数组，你最初位于数组的第一个位置。
数组中的每个元素代表你在该位置可以跳跃的最大长度。
判断你是否能够到达最后一个位置。
示例 1:
输入: [2,3,1,1,4]输出: true解释: 我们可
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2020-04-10
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/blog/categories/%E7%AE%97%E6%B3%95%E9%A2%98/" class="post-category">
                                    算法题
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/blog/tags/leetcode/">
                        <span class="chip bg-color">leetcode</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/blog/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/blog/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/blog/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/blog/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="https://sky508.gitee.io/blog/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">2019</span>
            <a href="/blog/about" target="_blank">glh</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/sky508/blog.git" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:17730269920@163.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=978742791" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 978742791" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







</div>
    </div>
</footer>



    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/blog/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/blog/search.xml", 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="https://sky508.gitee.io/blog/libs/materialize/materialize.min.js"></script>
    <script src="https://sky508.gitee.io/blog/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="https://sky508.gitee.io/blog/libs/aos/aos.js"></script>
    <script src="https://sky508.gitee.io/blog/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="https://sky508.gitee.io/blog/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/blog/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

    
    <script src="https://sky508.gitee.io/blog/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="https://sky508.gitee.io/blog/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    

    
    <script src="https://sky508.gitee.io/blog/libs/instantpage/instantpage.js" type="module"></script>
    

<script>
            window.imageLazyLoadSetting = {
                isSPA: false,
                processImages: null,
            };
        </script><script>window.addEventListener("load",function(){var t=/\.(gif|jpg|jpeg|tiff|png)$/i,r=/^data:image\/[a-z]+;base64,/;Array.prototype.slice.call(document.querySelectorAll("img[data-original]")).forEach(function(a){var e=a.parentNode;"A"===e.tagName&&(e.href.match(t)||e.href.match(r))&&(e.href=a.dataset.original)})});</script><script>!function(n){n.imageLazyLoadSetting.processImages=o;var i=n.imageLazyLoadSetting.isSPA,r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]"));function o(){i&&(r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]")));for(var t,e,a=0;a<r.length;a++)t=r[a],0<=(e=t.getBoundingClientRect()).bottom&&0<=e.left&&e.top<=(n.innerHeight||document.documentElement.clientHeight)&&function(){var t,e,n,i,o=r[a];t=o,e=function(){r=r.filter(function(t){return o!==t})},n=new Image,i=t.getAttribute("data-original"),n.onload=function(){t.src=i,e&&e()},n.src=i}()}o(),n.addEventListener("scroll",function(){var t,e;t=o,e=n,clearTimeout(t.tId),t.tId=setTimeout(function(){t.call(e)},500)})}(this);</script></body>

</html>
